package com.hotel.customersystem.controller;

import com.hotel.customersystem.service.KudosService;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 点赞功能
 */
@Api(value = "KudosController",tags = {"点赞模块"})
@RestController
@RequestMapping("kudos")
public class KudosController {
    @Autowired
    private KudosService kudosService;

    //查看 登录用户 是否已经点赞 该评论
    @GetMapping("/ifCommentHasKudos/{commentId}/{userId}")
    public boolean ifCommentHasKudos(@PathVariable("commentId") String commentId,
                                     @PathVariable("userId") String userId){
        boolean has = kudosService.hasKudos(commentId,userId);
        System.out.println("********************是否已经点赞"+has);
        return has;
    }

    //点赞
    @GetMapping("/doKudos/{commentId}/{userId}")
    public boolean doKudos(@PathVariable("commentId") String commentId,
                                     @PathVariable("userId") String userId){
        boolean result = kudosService.doKudos(commentId,userId);
        return result;
    }

    //取消点赞
    @GetMapping("/undoKudos/{commentId}/{userId}")
    public boolean undoKudos(@PathVariable("commentId") String commentId,
                           @PathVariable("userId") String userId){
        boolean result = kudosService.undoKudos(commentId,userId);
        return result;
    }

    //查看 点赞 总数
    @GetMapping("/getKudosNum/{commentId}")
    public Long getKudosNum(@PathVariable("commentId") String commentId){
        Long num =kudosService.kudosNum(commentId);
        return num;
    }
}
